package com.zhentao.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.zhentao.pojo.ParamCategory;
import com.zhentao.service.ParamCategoryService;
import com.zhentao.util.Result;
import com.zhentao.vo.ParamCategoryTreeVO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Tag(name = "参数分类", description = "参数分类查询接口")
@RestController
@RequestMapping("/param/category")
@RequiredArgsConstructor
@Slf4j
public class ParamCategoryController {

    private final ParamCategoryService paramCategoryService;

    @Operation(summary = "分类列表", description = "查询启用的参数分类列表")
    @GetMapping("/list")
    public Result list() {
        List<ParamCategory> list = paramCategoryService.list(
                new LambdaQueryWrapper<ParamCategory>()
                        .eq(ParamCategory::getStatus, 1)
                        .orderByAsc(ParamCategory::getSortOrder)
                        .orderByAsc(ParamCategory::getCreateTime)
        );
        return Result.OK(list);
    }

    @Operation(summary = "分类树", description = "查询参数分类树形结构")
    @GetMapping("/tree")
    public Result tree() {
        List<ParamCategoryTreeVO> tree = paramCategoryService.getCategoryTree();
        return Result.OK(tree);
    }
}









